<?php
html::printPath('public.home-header', 'public.home-desc');
$msg->printMessages();

echo '<div id="strilkyPictureFrame">' . html::img('strilky/strilky-1.jpg') . '</div>';

$languageNames = constants::$languageNames;

$languages = Kohana::config('multi_lang.allowed_languages');
if (count($languages) > 1) {
	echo '<ul class="languageList">';
	foreach ($languages as $langCode => $longName) {
		$langName = $languageNames[$langCode];
		echo '<li>' . html::anchor(url::current_lang($langCode), $langName . html::img('flag/lang/' . $langCode . '.png', array('alt' => $langCode, 'title' => $langName))) . '</li>';
	}
	echo '</ul>';
}

echo '<div id="loginBlock">';
echo '<ul class="commandList">';
echo '<li class="accountCommand">' . text::getEscaped('public.haveNoAccount') . ' ' .
    html::anchor('/signUp', text::get('public.createNewAccount')) . '.</li>';
echo '<li class="forgottenPasswordAction">' . html::anchor('/auth/forgottenPasswordForm', text::get('public.didYouForgetPassword')) . '?</li>';
echo '</ul>';

$fb = new FormBuilder('account', $formData);
$fb->secureConnection();
$fb->setFormId('loginForm');
$fb->setAction('/auth/loginUser');
$fb->text('userLogin')->required()->labelKey('person.login');
$fb->password('userPassword')->required()->labelKey('person.password');
$fb->submitButton('button.signIn');
$fb->write();

echo '</div>';
echo '<div style="clear: both"></div>';
?>

<script type="text/javascript">
    $(document).ready(function() {
        loadNextPicture();
        setTimeout(switchImages, 3500);
    });

    function loadNextPicture() {
        var pictureFrame = document.getElementById('strilkyPictureFrame');
        var img = pictureFrame.firstChild;
        var imgNumber = parseInt(img.src.replace(/.*strilky-([0-9]+)\.jpg/, '$1')) + 1;
        if (imgNumber > 12) {
            imgNumber = 1;
        }
        img.setAttribute('style', 'z-index: 2');
        var newImg = document.createElement('img');
        newImg.setAttribute('style', 'z-index: 1');
        newImg.setAttribute('src', img.src.replace(/(.*strilky-)[0-9]+.jpg/, '$1' + imgNumber + '.jpg'));
        pictureFrame.appendChild(newImg);
    }

    function switchImages() {
        var pictureFrame = document.getElementById('strilkyPictureFrame');
        var img = pictureFrame.firstChild;
        $(img).fadeOut();
        setTimeout(removeOldAndLoadNewImage, 500);
        setTimeout(switchImages, 3500);
    }
    function removeOldAndLoadNewImage() {
        var pictureFrame = document.getElementById('strilkyPictureFrame');
        pictureFrame.removeChild(pictureFrame.firstChild);
        loadNextPicture();
    }
</script>
